<%@page contentType="text/html; charset=UTF-8" %>
<jsp:useBean id="user" class="entity_beans.User" scope="session"></jsp:useBean>
<jsp:useBean id="auxBean" class="model.AuxBean" scope="request"></jsp:useBean>

<%@page import="entity_beans.Flight" %>
<%@page import="entity_beans.Passenger" %>
<%@page import="utils.DateTest"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Air Transport - Passenger Details</title>
</head>
<body>
<%!Passenger passenger = null;%>
<%
	if (user.isAccessed() == false) {
		response.sendRedirect("../index.jsp");
		return;
	}

	if ( user.isLoggedIn() == false ) {
		response.sendRedirect("../index.jsp");
		return;
	}
	
	String jmbg = request.getParameter("jmbg");
	
	passenger = auxBean.getPassengerByJMBG(jmbg);
	
	if (passenger == null) {
		response.sendRedirect("main.jsp");
		return;
	}
%>



<h2><u>Air Transport Service - Passenger Details</u></h2>

<jsp:include page="header.jsp"></jsp:include>

<%
	if (auxBean.getFlightsByPassenger(passenger.getJmbg()).size() != 0) {
%>

Flights: <br>
	<table border="1">
		<tr bgcolor="lightgrey">
			<th>No</th>
			<th>Flight ID</th>
			<th>Deparutre Time</th>
			<th>Arrival Time</th>
			<th>Source</th>
			<th>Destination</th>
			<th>Cancellation</th>
		</tr>
<%
	String bgColor = "#99CCFF";

	int i = 0;

	for (Flight flight : auxBean.getFlightsByPassenger(passenger.getJmbg())) {
		if (i % 2 == 0) {
	bgColor = "#99CCFF";
		}
		else {
	bgColor = "#CCCCCC";
		}
%>
		<tr bgcolor= <%= bgColor %>>
		<td align="center"><%=(i+1)%>.</td>
		<td align="center"><a href='flight.jsp?flightid=<%=flight.getId()%>'><%=flight.getId()%></a></td>
		<td align="center"><%=flight.getDepartureTimeFormated()%></td>
		<td align="center"><%=flight.getArrivalTimeFormated()%></td>
		<td align="center"><%=flight.getSource()%></td>
		<td align="center"><%=flight.getDestination()%></td>

		<%
			if (DateTest.testDate(flight.getDepartureTime()) == false) {
		%>
				<form method="get" action="cancellation.jsp">
					<td align="center">	
						<input type="hidden" name="jmbg" value=<%= passenger.getJmbg().toString() %>>
						<input type="hidden" name="flightid" value=<%= flight.getId() %>>
						<input type="submit" value="Cancel">
					</td>
				</form>
			
		<%
			} else {
		%>
			<td>Cancel Exp.</td>
		<%
			}
		%>
		</tr>
<%
	i++;
	}
%>		
</table>
<%
}
else {
%>
	Ne postoji nijedan let!<br />
<%
}
%>


<hr />
<p>
<a href="main.jsp">Main Page - Flight List</a>
</p>

	
<jsp:include page="footer.jsp"></jsp:include>
		
</body></html>